import { RequestTypes } from "@/const";
function concaturl(url) {
  return window.RPConfig.mgt.concat(`/tenant/${url}`);
}
function application(url) {
  return window.RPConfig.mgt.concat(`/application/${url}`);
}
// 查询list
export const getTenantList = ({ responseProcess, param }) => {
  $http.post(concaturl("findTenantPage"), param).then(res => {
    responseProcess(res.data);
  });
};

export const findTenantList = () => $http.post(concaturl("findTenantPage"), { pageSize: 9999, pageNum: 1 });
export const listProductByTenantCode = TenantCode =>
  $http.post(window.RPConfig.mgt + "/application/listProductByTenantCode", {
    TenantCode,
    requestType: RequestTypes.Query
  });

// 删除
export const delTenant = id => $http.post(concaturl(`delete?id=${id}`));

// get by id
export const getTenantById = id => $http.get(concaturl(`get?id=${id}`));

// 保存和添加
export const saveOrUpdateTenant = param => $http.post(concaturl(`${!!param.id ? "update" : "add"}`), param);

// 获取用户中心列表
export const getUserCenterList = () => $http.post(`${window.RPConfig.user}/getUserCenterList`);

// 导入组
export const importGroup = users => $http.post(`${window.RPConfig.baseURL}/sys/account/add/batch`, users);

// 新建时获取应用列表数据
export const findApplicationList = param =>
  $http.post(`${window.RPConfig.mgt}/application/getTenantAppListByTenantCode`, param);

// 更新通过租户ID获取
export const getTenantApplicationList = id =>
  $http.get(`${window.RPConfig.mgt}/tenant/getTenantApplicationList?tenantCode=${id}`);

// 获取分配应用选择器列表：数字化所有应用的应用编码
export const getApplicationByTenantCode = tenantCode =>
  $http.post(`${window.RPConfig.mgt}/application/getApplicationByTenantCode?tenantCode=${tenantCode}`);

// 获取当前租户的配置租户的用户中心和组织中心
export const getTenantConfigValue = param =>
  $http.post(
    `${window.RPConfig.mgt}/config/getTenantConfigValue?tenantCode=${param.tenantCode}&configCode=${param.configCode}`,
    param
  );
// 分配用户
export const assignUser = param =>
  $http.post(`${window.RPConfig.mgt}/role/authorizeRoleForUsers`, param, null, {
    headers: { orgTenantCode: param.tenantCode }
  });
export const batchAddTenantAdmin = params => $http.post(`${window.RPConfig.mgt}/user/batch/add`, params);

// 移除已分配用户
export const deleteAssignedUser = param => $http.post(`${window.RPConfig.mgt}/role/deleteRoleForUsers`, param);

//没有默认用户中心时移除分配用户
export const deleteAssignedUser2 = param =>
  $http.post(`${window.RPConfig.mgt}/role/deleteRoleForUsers`, param, null, {
    headers: { orgTenantCode: param.tenantCode }
  });

// 查询已分配的用户
export const queryAssignedUser = param =>
  $http.post(`${window.RPConfig.mgt}/user/getUserListPages`, param, null, {
    headers: { tenantCode: param.tenantCode }
  });

// 查询未分配的用户
export const queryUnAssignedUser = param =>
  $http.post(`${window.RPConfig.mgt}/user/getUserListPages`, param, null, {
    headers: { tenantCode: param.tenantCode }
  });

// 添加配置中心
export const addOrUpdateConfigValue = (param, addOrUpdate) => {
  return $http.post(`${window.RPConfig.mgt}/config/value/${addOrUpdate}`, param).then(response => response.data);
};

// 获取角色
export const getRoleByRoleCode = roleCode => {
  return $http
    .get(`${window.RPConfig.mgt}/role/getRoleByRoleCode?roleCode=${roleCode}`)
    .then(response => response.data);
};

// 查询租户数据统计list
export const getTenantDataStatisticsList = ({ responseProcess, param }) => {
  $http.post(`${window.RPConfig.mgt}/reportForms/getReportForms`, param).then(res => {
    responseProcess(res.data);
  });
};

// 刷新租户数据统计
export const refreshTenantDataStatistics = () => {
  return $http.post(`${window.RPConfig.mgt}/reportForms/addReportForms`).then(response => response.data);
};
